package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyInfo;
import com.ruoyi.system.service.ISysCompanyInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司信息管理Controller
 * 
 * @author ruoyi
 * @date 2022-03-10
 */
@RestController
@RequestMapping("/system/info")
public class SysCompanyInfoController extends BaseController
{
    @Autowired
    private ISysCompanyInfoService sysCompanyInfoService;

    /**
     * 查询公司信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCompanyInfo sysCompanyInfo)
    {
        startPage();
        List<SysCompanyInfo> list = sysCompanyInfoService.selectSysCompanyInfoList(sysCompanyInfo);
        return getDataTable(list);
    }

    /**
     * 导出公司信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "公司信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyInfo sysCompanyInfo)
    {
        List<SysCompanyInfo> list = sysCompanyInfoService.selectSysCompanyInfoList(sysCompanyInfo);
        ExcelUtil<SysCompanyInfo> util = new ExcelUtil<SysCompanyInfo>(SysCompanyInfo.class);
        util.exportExcel(response, list, "公司信息管理数据");
    }

    /**
     * 获取公司信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{companyInfoId}")
    public AjaxResult getInfo(@PathVariable("companyInfoId") Long companyInfoId)
    {
        return AjaxResult.success(sysCompanyInfoService.selectSysCompanyInfoByCompanyInfoId(companyInfoId));
    }

    /**
     * 新增公司信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "公司信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCompanyInfo sysCompanyInfo)
    {
        sysCompanyInfo.setCreateBy(getUsername());
        return toAjax(sysCompanyInfoService.insertSysCompanyInfo(sysCompanyInfo));
    }

    /**
     * 修改公司信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "公司信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCompanyInfo sysCompanyInfo)
    {
        sysCompanyInfo.setUpdateBy(getUsername());
        return toAjax(sysCompanyInfoService.updateSysCompanyInfo(sysCompanyInfo));
    }

    /**
     * 删除公司信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "公司信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyInfoIds}")
    public AjaxResult remove(@PathVariable Long[] companyInfoIds)
    {
        return toAjax(sysCompanyInfoService.deleteSysCompanyInfoByCompanyInfoIds(companyInfoIds));
    }
}
